package ac.svn.accesscontrol.store;

import java.util.HashSet;
import java.util.Set;

import ac.svn.accesscontrol.manager.SVNInfoManager;

public class SVNLocation implements ISVNItem ,Comparable<SVNLocation>{

	private String locationPath;
	private String locationName;
	private Set<String> accessUnits;
	private String comments;


	public String getLocationPath() {
		return locationPath;
	}
	public void setLocationPath(String locationPath) {
		this.locationPath = locationPath;
	}
	public String getLocationName() {
		return locationName;
	}
	public void setLocationName(String locationName) {
		this.locationName = locationName;
	}
	public Set<String> getAccessUnits() {
		return accessUnits;
	}

	public void addAccessUnit(String accessUnitId)
	{
		this.accessUnits.add(accessUnitId);
	}

	public void removeAccessUnit(AccessUnit accessUnit )
	{
		this.accessUnits.remove(accessUnit);
	}
	@Override
	public String toString() {
		return "SVNLocation [locationPath=" + locationPath + ", locationName="
				+ locationName + ", accessUnits=" + accessUnits + "]";
	}
	public SVNLocation() {
		super();
		accessUnits = new HashSet<String>(); 
	}

	public SVNLocation(String locationPath, String locationName) {
		super();
		this.locationPath = locationPath;
		this.locationName = locationName;
	}
	@Override
	public String getName() {
		return getLocationName();
	}
	@Override
	public int compareTo(SVNLocation o) {
		return locationPath.compareTo(o.getLocationPath());
	}
	@Override
	public String getTooltipText() {
		String str = "<HTML>SVNLocation <br>LocationPath=" + locationPath + "<br>LocationName="
				+ locationName + "<br>[Access Via]<br>";
		for(String accessUnitId : accessUnits)
		{
			AccessUnit  accessUnit = SVNInfoManager.getInfoManager().getAccessUnit(accessUnitId);
			if(null != accessUnit)
			{
				str += "-" + accessUnit.getOwnerId() + "<br>";
			}					
		}
		str += "</HTML>";
		return str;
	}
	
	@Override
	public String getId() 
	{
		return locationPath;
	}
	/**
	 * @param accessUnits the accessUnits to set
	 */
	public void setAccessUnits(Set<String> accessUnits) {
		this.accessUnits = accessUnits;
	}
	/**
	 * @return the comments
	 */
	public String getComments() {
		return comments;
	}
	/**
	 * @param comments the comments to set
	 */
	public void setComments(String comments) {
		this.comments = comments;
	}
	@Override
	public String getMetaData() {
	    return String.format("%s|%s|%s", locationName,locationPath,comments);
	}






}
